<template>
  <div class="app-main-content">
    <el-form ref="queryForm" :inline="true" :model="queryForm" label-suffix=" :" @submit.native.prevent>
      <el-form-item label="查询条件" prop="value">
        <el-input v-model.trim="queryForm.value" placeholder="请输入角色名称" @keyup.enter.native="onSearch('queryForm')" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSearch('queryForm')">查询</el-button>
        <el-button @click="onReset('queryForm')">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
      <el-button type="danger" icon="el-icon-delete" :loading="delBtnLoading" :disabled="!selected.length" @click="handleDeleteAll">删除</el-button>
    </el-row>
    <scmsa-table
      v-loading="tableLoading"
      class="margin-top-12"
      :data="tableData"
      :column="tableColumn"
      border
      :pagination="true"
      :current-page="currentPage"
      :page-size="pageSize"
      :total="totalPage"
      @size-change="handlePageSizeChange({v: arguments[0], refreshName: 'fetchAll'})"
      @pagination-current-change="handlePageCurrentChange({v: arguments[0], refreshName: 'fetchAll'})"
      @selection-change="handleSelectionChange"
    />
    <el-drawer
      ref="drawer"
      :title="title"
      :visible.sync="dialog"
      direction="rtl"
      size="400px"
      :destroy-on-close="true"
      :modal-append-to-body="false"
      :wrapper-closable="false"
      @close="resetFieldsForm('actionForm')"
    >
      <div class="drawer__content">
        <scmsa-simple-form ref="actionForm" :model="actionForm" :rules="actionRules" label-suffix=" :" label-width="100px" :action-form-config="actionFormConfig" />
        <div class="drawer__footer">
          <el-button @click="dialog = false">取 消</el-button>
          <el-button type="primary" :loading="loading" @click="onSubmit('actionForm')">{{ loading ? '提交中 ...' : '确定' }}</el-button>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
  import table from '@/mixins/table'
  import form from '@/mixins/form'
  import actionMixin from '@/mixins/actions-mixins'
  import dialogMixin from '@/mixins/dialog-mixins'
  export default {
    name: 'SingleTableMixing',
    mixins: [table, form, actionMixin, dialogMixin],
    data() {
      return {
        /*getAll: () => {}, //获取列表数据api函数
        createRecord: () => {}, // 新增数据api函数
        getRecord: () => {}, // 获取详情api函数
        updateRecord: () => {}, // 编辑数据api函数
        removeRecord: () => {}, // 删除数据api函数*/
        pageName: '角色',
        actionRules: {
          name: [
            { required: true, message: '请输入角色名称', trigger: 'blur' }
          ]
        },
        params: {
          page: 1,
          limit: 10
        },
        tableData: [
          {
            name: 'UI设计师',
            describe: '指从事对软件的人机交互、操作逻辑、界面美观的整体设计工作的人'
          },
          {
            name: '前端工程师',
            describe: 'Web前端工程师的职责是编写网页标准优化代码'
          }
        ]
      }
    },
    computed: {
      domain() {
        return [{
          type: 'selection',
          width: 55,
          align: 'center',
          formHide: true // 表单隐藏
        }, {
          prop: 'name',
          label: '角色名称',
          defaultValue: 'Java工程师',
          dataType: 'string' // 数据类型
        }, {
          prop: 'describe',
          label: '角色描述',
          dataType: 'string',
          attrs: { // attrs form表单属性
            type: 'textarea'
          }
        }, {
          label: '操作',
          width: 200,
          formHide: true,
          render: (h, params) => {
            return h('div', [
              h('el-button', {
                props: {
                  type: 'text',
                  size: 'small',
                  icon: 'el-icon-edit',
                  loading: this.initActionLoading(params, 'edit')
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    this.handleEdit(params)
                  }
                }
              }, '编辑'),
              h('el-divider', {
                props: {
                  direction: 'vertical'
                }
              }),
              h('el-button', {
                props: {
                  type: 'text',
                  size: 'small',
                  icon: 'el-icon-delete',
                  loading: this.initActionLoading(params, 'del')
                },
                on: {
                  click: () => {
                    this.handleDelete(params)
                  }
                }
              }, '删除')
            ])
          }
        }]
      }
    },
    methods: {
      // 获取列表的回调函数
      getAllCallback(res) {
        this.tableData = res.data || []
        this.totalPage = res.total
      }
    }
  }
</script>

<style scoped>
</style>
